package com.asset.salesforce.activities;

import com.asset.salesforce.R;
import com.asset.salesforce.handlers.MenuHandler;


import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends ListActivity {
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        
	        String[] items = getResources().getStringArray(R.array.items);
	        this.setListAdapter(new ArrayAdapter<String>(this,
			        R.layout.main, 
			        items));
	        
	        ListView lv = getListView();

	        // listening to single list item on click
	        lv.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
	              int position, long id) {
	        	  //Toast.makeText(getApplicationContext(), ((TextView) view).getText(),Toast.LENGTH_SHORT).show();
	        	  String sText = ((TextView) view).getText().toString();
	              Intent intent = null;
	              if(sText.equals("Leads"))
	              intent = new Intent(getBaseContext(),LeadActivity.class);
	              else if(sText.equals("Accounts"))
	            	  intent = new Intent(getBaseContext(),AccountActivity.class);
	              else if(sText.equals("Contacts"))
	            	  intent = new Intent(getBaseContext(),ContactActivity.class);
	              else if(sText.equals("Dashboard"))
	            	  intent = new Intent(getBaseContext(),DashboardActivity.class);
	              if(intent != null)
	  				startActivity(intent);
	          }
	        });
	    }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	public boolean onOptionsItemSelected(android.view.MenuItem item) {
		MenuHandler.handleOnItemSelected(item, this);
		return super.onOptionsItemSelected(item);
	};
}
